<?php

class work_daysActions extends sfActions {

    public function executeText_save(sfWebRequest $request){
        $content = $request->getParameter('content');

        $c = new Criteria();
        $c->add(TextsPeer::SLUG, 'jornadas');
        $text = TextsPeer::doSelectOne($c);
        $text->setContent($content);
        $text->save();

        $this->getUser()->setFlash('msg','Los cambios se guardaron satisfactoriamente');
        $this->redirect('@work_days');
    }

    public function executeIndex(sfWebRequest $request){
        $c = new Criteria();

       
        $c->clear();
        $c->add(WorkDaysPeer::ENABLED, 1);
        $c->addAscendingOrderByColumn(WorkDaysPeer::ORDER);

        $pager = new sfPropelPager('WorkDays', sfConfig::get('app_max_per_page'));
        $pager->setCriteria($c);
        $pager->setPage($request->getParameter('page', 1));
        $pager->init();
        $this->pager = $pager;
    }

    public function executeNew(sfWebRequest $request){

    }

    public function executeNew_save(sfWebRequest $request){
        $name = $request->getParameter('name');
        $content = $request->getParameter('content');
        $is_solved = $request->getParameter('is_solved', 0);//1 or empty
        $resolution = $request->getParameter('resolution');
        $order = $request->getParameter('order');
        $titu_fecha=$request->getParameter('titufecha');
        $resumen=$request->getParameter('resumen');
        $fechafin=$request->getParameter('fecha');
  




        $day = substr($fechafin,0,2);
        $month = substr($fechafin,3,2);
        $year = substr($fechafin,6,4);
        $f_date = $year."-".$month."-".$day;

        if($is_solved!=''){ $is_solved = 1; }

        $work_day = new WorkDays();
        $work_day->setName($name);
        $work_day->setContent($content);
        $work_day->setIsSolved($is_solved);
        $work_day->setResolution($resolution);
        $work_day->setEnabled(1);
        $work_day->setOrder($order);
        $work_day->setFechajornada($titu_fecha);
        $work_day->setResumen($resumen);
        $work_day->setFechaFin($f_date);


        $work_day->save();

        $this->getUser()->setFlash('msg','Jornada creada satisfactoriamente');
        $this->redirect('@work_days');
    }

    public function executeEdit(sfWebRequest $request){
        $id = $request->getParameter('id');
        $this->work_day = WorkDaysPeer::retrieveByPK($id);
    }

    public function executeEdit_save(sfWebRequest $request){
        $hdId = $request->getParameter('hdId');
        $name = $request->getParameter('name');
        $content = $request->getParameter('content');
        $is_solved = $request->getParameter('is_solved', 0);//1 or empty
        $resolution = $request->getParameter('resolution');
        $order = $request->getParameter('order');
        $resumen=$request->getParameter('resumen');
        $fechafin=$request->getParameter('fecha');
        $titu_fecha=$request->getParameter('titufecha');

        


        if($fechafin!="")
        {
             $day = substr($fechafin,0,2);
            $month = substr($fechafin,3,2);
            $year = substr($fechafin,6,4);
            $f_date = $year."-".$month."-".$day;
        }
       

        if($is_solved!=''){ $is_solved = 1; }

        $work_day = WorkDaysPeer::retrieveByPK($hdId);
        $work_day->setName($name);
        $work_day->setContent($content);
        $work_day->setIsSolved($is_solved);
        $work_day->setResolution($resolution);
        $work_day->setOrder($order);
        if($fechafin!="")
        {
          $work_day->setFechaFin($f_date);
        }
        
        $work_day->setFechajornada($titu_fecha);
        $work_day->setResumen($resumen);



        $work_day->save();
        $this->getUser()->setFlash('msg','Jornada modificado satisfactoriamente');
        $this->redirect('@work_days');
    }

    public function executeDelete(sfWebRequest $request){
        $id = $request->getParameter('id');
        $work_day = WorkDaysPeer::retrieveByPK($id);
        $work_day->delete();
      

        $this->getUser()->setFlash('msg','Jornada eliminado satisfactoriamente');
        $this->redirect('@work_days');
    }

}